package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/9/26 10:12
 * @apiNote
 */

public class Test02535DifferenceOfSum {
    public static void main(String[] args) {
        int[] nums = {1,15,6,3};
        int res = differenceOfSum(nums);
        System.out.println(res);
    }
    public static int differenceOfSum(int[] nums) {
        int n = nums.length;
        int sum1 = 0, sum2 = 0;
        for(int i = 0; i < n; i++){
            sum1 += nums[i];
            sum2 +=sumOfEach(nums[i]);
        }
        return Math.abs(sum1 - sum2);
    }
    public static int sumOfEach(int num){
        int sum = 0;
        while(num > 0){
            sum += num % 10;
            num /= 10;
        }
        return sum;
    }
}
